package lianxi;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class lianxitest1 {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student s1 = new Student("张三",23,"北京");
        Student s2 = new Student("李四",25,"上海");
        Student s3 = new Student("牛三",27,"天津");
        Student s4 = new Student("王五",26,"武汉");
        Student s5 = new Student("三五",26,"武汉");
        Student s6 = new Student("四五",26,"武汉");
        Student s7 = new Student("六五",26,"武汉");
        Student s8 = new Student("七五",26,"武汉");
        Collections.addAll(list,s1,s2,s3,s4,s5,s6,s7,s8);
        ArrayList<Student> list2 = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            floo:while (true){
                Random r = new Random();
                int index = r.nextInt(list.size());
                System.out.println(list.get(index).getName());
                list2.add(list.get(index));
                list.remove(index);
                if (list.isEmpty()){
                    System.out.println("这是第"+(i+1)+"次点名");
                    break floo;
                }
            }
           list.addAll(list2);
        }

    }
}
